<template>
  <div class="InspectionRecord">
    <NavBar fixed placeholder title="巡检记录" z-index="999" ref="nav">
      <template #left>
        <Icon
          name="arrow-left"
          size="0.53rem"
          color="#000"
          @click="$router.back()"
        />
      </template>
    </NavBar>
    <div class="item" v-for="(item, i) in list" :key="i">
      <div class="placeholder"></div>
      <div class="item-header">
        <div class="item-title">{{ item.eciName }}</div>
        <div class="item-flag" @click="item.flag = !item.flag">
          <Icon :name="item.flag ? 'arrow-up' : 'arrow-down'" />
          {{ item.flag ? "展开" : "收缩" }}
        </div>
      </div>
      <div class="main" v-show="item.flag">
        <div class="header">内容和方法</div>
        <div class="content">{{ item.text }}</div>
        <div class="header">判断标准</div>
        <div class="content">{{ item.requirem }}</div>
        <div class="header">检查结果</div>
        <div class="btns">
          <Button
            class="btn"
            :class="{ state: item.state == 0 }"
            @click="item.state = 0"
            >正常</Button
          >
          <Button
            class="btn"
            :class="{ state: item.state == 1 }"
            @click="item.state = 1"
            >异常</Button
          >
        </div>
        <div class="header">检查意见</div>
        <textarea v-model="item.idea"></textarea>
        <div class="header">照片</div>
        <Uploader
          class="uploader"
          v-model="item.fileList"
          multiple
          :max-count="2"
        />
      </div>
    </div>
    <div class="btn1-placeholder"></div>
    <img
      class="baoiu"
      style="width: 2.5rem"
      src="../../../assets/img/baoxiu.png"
      alt="11"
      @click="
        $router.push({
          name: 'EquipmentRepair',
          query: {
            id: '',
            name: '',
            describe: '',
          },
        })
      "
    />
    <Button class="btn1" @click="onSubmit">提交</Button>
  </div>
</template>

<script>
import {
  EquipmentPointCheckItems,
  EquipmentPointCheckItemsSubmit,
} from "@/api/work";
import {
  Image as VanImage,
  Uploader,
  Popup,
  NavBar,
  Icon,
  Field,
  Cell,
  List,
  Button,
  Toast,
} from "vant";
import uploadImages from "@/utils/uploadImages.js";
export default {
  props: {},
  data() {
    return {
      list: [],
    };
  },
  computed: {
    ImgFlag() {
      let flag = false;
      for (let i = 0; i < this.list.length; i++) {
        if (this.list[i].fileList.length <= 0) {
          flag = true;
        }
      }
      return flag;
    },
  },
  created() {},
  mounted() {
    this.getInfo();
  },
  watch: {},
  methods: {
    async getInfo() {
      const { param } = await EquipmentPointCheckItems({
        ...this.$route.query,
      });
      console.log(param.data);
      param.data.forEach((v, i) => {
        if (i == 0) {
          v.flag = true;
        } else {
          v.flag = false;
        }
        v.state = 0;
        v.fileList = [];
      });
      this.list = param.data;
    },
    async onSubmit() {
      if (this.ImgFlag) return Toast.fail("请拍摄照片");
      this.$toast.loading({
        message: "提交中...",
        duration: 0,
      });
      for (let i = 0; i < this.list.length; i++) {
        let pic = await uploadImages(this.list[i].fileList);
        this.list[i].pic = pic.join(",");
      }
      await EquipmentPointCheckItemsSubmit({
        item: this.list,
        ...this.$route.query,
      });
      this.$toast.success("提交成功！");
      // this.$router.push({
      //   name: "InspectionList",
      //   query: {
      //     state: "c",
      //   },
      // });
      this.$router.back();
    },
  },
  components: {
    VanImage,
    Uploader,
    Button,
    Popup,
    NavBar,
    Icon,
    Field,
    Cell,
    List,
    Toast,
  },
};
</script>

<style scoped lang="less">
@import "~@/style/var.less";
* {
  box-sizing: border-box;
}
.InspectionRecord {
  .flex {
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .placeholder {
    width: 100%;
    height: 20px;
    background-color: #f7f7f9;
  }
  .item {
    font-size: 30px;
    .item-header {
      padding: 0 20px;
      height: 70px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .item-flag {
        color: @primary;
      }
    }
    .main {
      .header {
        height: 60px;
        padding-left: 20px;
      }
      .content {
        height: 60px;
        padding-left: 40px;
      }
      .btns {
        margin: 10px 0 30px;
        .btn {
          width: 132px;
          height: 44px;
          border-radius: 22px;
          margin-left: 30px;
          color: @primary;

          background-color: #fff;
          border: 1px solid @primary;
        }
        .state {
          background: #f8e0ce;
          // border: 0;
        }
      }
      textarea {
        width: 95%;
        height: 180px;
        border: 1px solid #dddddd;
        border-radius: 12px;
        margin: 10px 20px 30px;
      }
      .van-uploader {
        margin: 20px;
      }
      /deep/.van-uploader__upload {
        border: 2px dashed #e16712;
        width: 110px;
        height: 110px;
        border-radius: 4px;
        background: #fff;
        .van-icon {
          color: rgb(225, 103, 18);
          &::before {
            content: "\F0A2";
          }
        }
      }
    }
  }
  .btn1-placeholder {
    height: 120px;
  }
  .btn1 {
    height: 98px;
    position: fixed;
    bottom: 10px;
    left: 50%;
    width: 90%;
    transform: translate(-50%);
    background: #fff;
    border-radius: 6px;
    font-weight: 500;
    color: @primary;
    border: 1px solid @primary;
    font-size: 36px;
  }
  .baoiu {
    position: fixed;
    right: 0;
    bottom: 30%;
  }
}
</style>